package com.yuanli.cosmeticmirror.utils;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Environment;
import android.os.SystemClock;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Patterns;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.yuanli.cosmeticmirror.base.Constant;
import com.yuanli.cosmeticmirror.base.WxConstant;

import java.io.File;
import java.security.MessageDigest;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CommonUtils {

    /**
     * 防止恶意点击使用
     */
    private static long LAST_CLICK_TIME;

    /**
     * 防止恶意点击
     *
     * @param interval 两次点击之间的最小间隔（秒）
     * @return true:允许点击
     */
    public static boolean isFastDoubleClick(int interval) {
        long time = SystemClock.uptimeMillis();
        if (time - LAST_CLICK_TIME > interval * 1000) {
            LAST_CLICK_TIME = time;
            return true;
        }
        return false;
    }

    /**
     * 获取路径字符串的父文件夹名称
     *
     * @param path
     * @return
     */
    public static String getParentFolderName(String path) {
        if (path == null) {
            return null;
        }
        String[] folders = path.split("/");
        if (folders.length >= 3) {
            return folders[folders.length - 2];
        }
        return folders[0];
    }


    /**
     * 复制内容到剪切板
     *
     * @param copyStr
     * @return
     */
    public static boolean copy(Context context, String copyStr) {
        try {
            //获取剪贴板管理器
            ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
            // 创建普通字符型ClipData
            ClipData mClipData = ClipData.newPlainText("Label", copyStr);
            // 将ClipData内容放到系统剪贴板里。
            cm.setPrimaryClip(mClipData);
            return true;
        } catch (Exception e) {
            return false;
        }
    }

    /**
     * 获取应用名称：音频提取
     *
     * @return
     */
    public static String getAppName() {
        return "音频提取";
    }


    /**
     * 获取一个唯一值，做id使用
     *
     * @return
     */
    public static String getUniqueNumber() {
        // 理论上存在重复的可能，所以在后面再加上一个随机字符串
        Random r = new Random();
        return System.nanoTime() + r.nextInt() + "";
    }


    /**
     * 检查网址是否有效
     *
     * @param strUrl
     * @return
     */
    public static boolean isUrlEffective(String strUrl) {
        return Patterns.WEB_URL.matcher(strUrl).matches();
    }

    /**
     * 验证手机格式
     *
     * @param phone
     */
    public static boolean checkPhone(String phone) {
        /*
         * 移动：134、135、136、137、138、139、150、151、157(TD)、158、159、187、188
         * 联通：130、131、132、152、155、156、185、186 电信：133、153、180、189、（1349卫通）
         * 总结起来就是第一位必定为1，第二位必定为3或5或8，其他位置的可以为0-9
         */
        if (phone == null) {
            return false;
        }
        // "[1]"代表第1位为数字1，"[358]"代表第二位可以为3、5、8中的一个，"\\d{9}"代表后面是可以是0～9的数字，有9位。
        String telRegex = "[1][3456789]\\d{9}";
        if (TextUtils.isEmpty(phone)) {
            return false;
        } else {
            return phone.matches(telRegex);
        }
    }

    /**
     * 字符串传Json
     *
     * @param names
     * @param strs
     * @return
     */
    public static String getJson(String[] names, String[] strs) {
        StringBuilder result = new StringBuilder("{\"");
        for (int i = 0; i < strs.length; i++) {
            result = result.append(names[i]).append("\"");
            result = result.append(":\"");
            result = result.append(strs[i]).append("\"");
            if (i < strs.length - 1) {
                result = result.append(",\"");
            }
        }
        result = result.append("}");
        return result.toString();
    }

    /**
     * 加密
     * 32位大写加密
     *
     * @param plaintext 明文
     * @return ciphertext 密文
     */
    public static String toMd5(String plaintext) {
        char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
                'A', 'B', 'C', 'D', 'E', 'F'};
        try {
            byte[] btInput = plaintext.getBytes();
            // 获得MD5摘要算法的 MessageDigest 对象
            MessageDigest mdInst = MessageDigest.getInstance("MD5");
            // 使用指定的字节更新摘要
            mdInst.update(btInput);
            // 获得密文
            byte[] md = mdInst.digest();
            // 把密文转换成十六进制的字符串形式
            int j = md.length;
            char str[] = new char[j * 2];
            int k = 0;
            for (int i = 0; i < j; i++) {
                byte byte0 = md[i];
                str[k++] = hexDigits[byte0 >>> 4 & 0xf];
                str[k++] = hexDigits[byte0 & 0xf];
            }
            return new String(str).toUpperCase();
        } catch (Exception e) {
            return null;
        }
    }


    /**
     * 获取设备ID
     *
     * @return
     */
    @SuppressLint("HardwareIds")
    public static String getDeviceId(Context context) {
        return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
    }

    /**
     * 手机型号
     *
     * @return
     */
    public static String getBrand() {
        return android.os.Build.BRAND;
    }

    /**
     * 获取版本信息
     *
     * @return
     * @throws Exception
     */
    public static String getVersionName(Context context) {
        try {
            PackageManager packageManager = context.getPackageManager();
            PackageInfo packInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
            return packInfo.versionName;
        } catch (PackageManager.NameNotFoundException e) {
        }
        return "";
    }

    /**
     * 得到随机字符串
     */
    public static String genNonceStr() {
        Random random = new Random();
        return MD5.getMessageDigest(String.valueOf(random.nextInt(10000)).getBytes());
    }

    /**
     * 获得app签名
     *
     * @param map
     * @return
     */
    public static String genAppSign(Map<String, String> map) {
        StringBuilder sb = new StringBuilder();

        for (Map.Entry<String, String> entry : map.entrySet()) {
            sb.append(entry.getKey());
            sb.append('=');
            sb.append(entry.getValue());
            sb.append('&');
        }
        /*for (int i = 0; i < map.size(); i++) {
            sb.append(params.get(i).getName());
            sb.append('=');
            sb.append(params.get(i).getValue());
            sb.append('&');
        }*/
        sb.append("key=");
        sb.append(WxConstant.WX_API_KEY);

        String appSign = MD5.getMessageDigest(sb.toString().getBytes()).toUpperCase();
        return appSign;
    }

    /**
     * 判断某一个activity是否存在任务栈里面 
     *
     * @param context
     * @param activity 被判断的activity
     * @return true 存在, false 不存在
     */
    public static boolean isExistMainActivity(Context context, Class<?> activity) {
        Intent intent = new Intent(context, activity);
        ComponentName cmpName = intent.resolveActivity(context.getPackageManager());
        if (cmpName != null) {
            // 说明系统中存在这个activity
            ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
            //获取从栈顶开始往下查找的10个activity
            List<ActivityManager.RunningTaskInfo> taskInfoList = am.getRunningTasks(10);
            for (ActivityManager.RunningTaskInfo taskInfo : taskInfoList) {
                // 说明它已经启动了
                if (taskInfo.baseActivity.equals(cmpName)) {
                    return true;
                }
            }
        }
        return false;
    }


    /**
     * 毫秒 转 mm:ss 时间转化
     *
     * @return
     */
    public static String millisecondToStr(int millisecond) {
        DateFormat df = new SimpleDateFormat("mm:ss", Locale.getDefault());
        try {
            return df.format(new Date(millisecond));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "00:00";
    }

    /**
     * 获取cache路径
     *
     * @param context
     * @return
     */
    public static String getDiskCachePath(Context context) {
        if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) {
            return context.getExternalCacheDir().getPath();
        } else {
            return context.getCacheDir().getAbsolutePath();
        }
    }

    //    /**
    //     * 获取缓存File路径
    //     * @param context
    //     * @param type 缓存文件累心
    //     * @return
    //     */
    //    public static String getCacheFilePath(Context context, int type) {
    //        String path = null;
    //        switch (type) {
    //            case CodeConstant.DYNAMIC_STICKER:
    //                String dynamicStickerPath;
    //                if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) {
    //                    dynamicStickerPath = context.getExternalFilesDir("dynamic_sticker").getPath();
    //                } else {
    //                    dynamicStickerPath = context.getFilesDir().getAbsolutePath() + File.separator + "dynamic_sticker";
    //                    FileUtils.createDirs(dynamicStickerPath);
    //                }
    //                path = dynamicStickerPath;
    //                break;
    //            case CodeConstant.TTF:
    //                String ttfPath;
    //                if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) {
    //                    ttfPath = context.getExternalFilesDir("TTF").getPath();
    //                } else {
    //                    ttfPath = context.getFilesDir().getAbsolutePath() + File.separator + "TTF";
    //                    FileUtils.createDirs(ttfPath);
    //                }
    //                path = ttfPath;
    //                break;
    //            case CodeConstant.VIDEO_BOX:
    //                String boxPath;
    //                if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) {
    //                    boxPath = context.getExternalFilesDir("box").getPath();
    //                } else {
    //                    boxPath = context.getFilesDir().getAbsolutePath() + File.separator + "box";
    //                    FileUtils.createDirs(boxPath);
    //                }
    //                path = boxPath;
    //                break;
    //            case CodeConstant.SHAPE:
    //                String shapePath;
    //                if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) {
    //                    shapePath = context.getExternalFilesDir("shape").getPath();
    //                } else {
    //                    shapePath = context.getFilesDir().getAbsolutePath() + File.separator + "shape";
    //                    FileUtils.createDirs(shapePath);
    //                }
    //                path = shapePath;
    //                break;
    //            case CodeConstant.MUSIC:
    //                String musicPath;
    //                if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) {
    //                    musicPath = context.getExternalFilesDir("bgMusic").getPath();
    //                } else {
    //                    musicPath = context.getFilesDir().getAbsolutePath() + File.separator + "bgMusic";
    //                    FileUtils.createDirs(musicPath);
    //                }
    //                path = musicPath;
    //                break;
    //            case CodeConstant.STICKER:
    //                String stickerPath;
    //                if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) {
    //                    stickerPath = context.getExternalFilesDir("sticker").getPath();
    //                } else {
    //                    stickerPath = context.getFilesDir().getAbsolutePath() + File.separator + "sticker";
    //                    FileUtils.createDirs(stickerPath);
    //                }
    //                path = stickerPath;
    //                break;
    //
    //            case CodeConstant.PICTURE:
    //                String picturePath;
    //                if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) {
    //                    picturePath = context.getExternalFilesDir("picture").getPath();
    //                } else {
    //                    picturePath = context.getFilesDir().getAbsolutePath() + File.separator + "picture";
    //                    FileUtils.createDirs(picturePath);
    //                }
    //                path = picturePath;
    //                break;
    //            case CodeConstant.WATER:
    //                String waterPath;
    //                if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) {
    //                    waterPath = context.getExternalFilesDir("water").getPath();
    //                } else {
    //                    waterPath = context.getFilesDir().getAbsolutePath() + File.separator + "water";
    //                    FileUtils.createDirs(waterPath);
    //                }
    //                path = waterPath;
    //                break;
    //            case CodeConstant.WATER_BG:
    //                String waterBgPath;
    //                if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) {
    //                    waterBgPath = context.getExternalFilesDir("waterBg").getPath();
    //                } else {
    //                    waterBgPath = context.getFilesDir().getAbsolutePath() + File.separator + "waterBg";
    //                    FileUtils.createDirs(waterBgPath);
    //                }
    //                path = waterBgPath;
    //                break;
    //            case CodeConstant.MY_WATER_IMG:
    //                String myWaterPath;
    //                if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) {
    //                    myWaterPath = context.getExternalFilesDir("myWaterImg").getPath();
    //                } else {
    //                    myWaterPath = context.getFilesDir().getAbsolutePath() + File.separator + "myWaterImg";
    //                    FileUtils.createDirs(myWaterPath);
    //                }
    //                path = myWaterPath;
    //                break;
    //            case CodeConstant.MY_WATER_DIY:
    //                String myWaterDiyPath;
    //                if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) {
    //                    myWaterDiyPath = context.getExternalFilesDir("myWaterDiy").getPath();
    //                } else {
    //                    myWaterDiyPath = context.getFilesDir().getAbsolutePath() + File.separator + "myWaterDiy";
    //                    FileUtils.createDirs(myWaterDiyPath);
    //                }
    //                path = myWaterDiyPath;
    //                break;
    //                default:break;
    //        }
    //
    //
    //        return path;
    //    }


    /**
     * 获取缓存文件名称
     *
     * @param context
     * @param fileName
     * @return
     */
    public static String getDiskCacheFilePath_Mm3(Context context, String fileName) {
        return getDiskCachePath(context) + File.separator + fileName + ".mp3";
    }

    /**
     * 获取缓存文件名称（录音使用）
     *
     * @param context
     * @param fileName
     * @return
     */
    public static String getDiskCacheFilePath_Wav(Context context, String fileName) {
        return getDiskCachePath(context) + File.separator + fileName + ".wav";
    }

    //    /**
    //     * 获取用户作品文件路径
    //     * @param userId 用户名
    //     * @param typeCode 作品类型 作品/录音
    //     * @param fileName 作品名称（不带后缀）
    //     * @return 作品完整路径/null
    //     */
    //    public static String getUserFilePath(String userId, int typeCode, String fileName){
    //        if (userId != null && fileName != null && !"".equals(fileName.trim())){
    //            //拼接用户文件夹路径
    //            String userFolder = getUserFolderById(userId, 1);
    //            if (userFolder != null) {
    //
    //                //拼接用户作品文件夹路径
    //                String workPath = null;
    //
    //                if (typeCode == UserWork.TYPE_CODE_WORK){
    //                    workPath = getUserFolderById(userId, 2);
    //                    fileName += ".mp3";
    //
    //                }else if (typeCode == UserWork.TYPE_CODE_RECORDER){
    //                    workPath = getUserFolderById(userId, 3);
    //                    fileName += ".wav";
    //                }
    //
    //                if (workPath != null){
    //                    if (RxFileTool.createOrExistsDir(workPath)) {
    //                        //拼接文件路径
    //                        String filePath = workPath + File.separator + fileName;
    //                        FileUtils.isDel(filePath);
    //                        return filePath;
    //                    }
    //                }
    //            }
    //        }
    //        return null;
    //    }

    //    /**
    //     * 根据类型获取对应文件夹路径
    //     * @param userId 用户id
    //     * @param typeCode 文件夹类型：
    //     * {
    //     *   1：用户文件夹，2：用户作品文件夹，3：用户录音文件夹，
    //     *   4：头像文件夹, 5：音频提取界面下载文件夹, 6：素材库界面下载文件夹,
    //     *   7：空白音文件夹， 8：导出文本文件夹
    //     * }
    //     * @return 如果不存在或创建失败返回null
    //     */
    //    public static String getUserFolderById(String userId, int typeCode){
    //        if (userId != null){
    //            String path = null;
    //            switch (typeCode){
    //                case 1:
    //                    //拼接返回用户文件夹路径
    //                    path = AppPathConstant.PATH_APP_ROOT_FOLDER + File.separator + userId;
    //                    break;
    //                case 2:
    //                    //拼接返回用户作品文件夹路径
    //                    path = AppPathConstant.PATH_APP_ROOT_FOLDER + File.separator +  userId + AppPathConstant.PATH_USER_WORK_FOLDER;
    //                    break;
    //                case 3:
    //                    //拼接返回用户录音文件夹路径
    //                    path = AppPathConstant.PATH_APP_ROOT_FOLDER + File.separator +  userId + AppPathConstant.PATH_USER_RECORDER_FOLDER;
    //                    break;
    //                case 4:
    //                    //拼接返回用户头像文件夹路径
    //                    path = AppPathConstant.PATH_APP_ROOT_FOLDER + File.separator +  userId + AppPathConstant.PATH_PIC_FOLDER;
    //                    break;
    //                case 5:
    //                    //拼接返回用户在音频提取界面的下载文件夹路径
    //                    path = AppPathConstant.PATH_APP_ROOT_FOLDER + File.separator +  userId + AppPathConstant.PATH_DOWNLOAD_FOLDER_01;
    //                    break;
    //                case 6:
    //                    //拼接返回用户在素材库界面的下载文件夹路径
    //                    path = AppPathConstant.PATH_APP_ROOT_FOLDER + File.separator +  userId + AppPathConstant.PATH_DOWNLOAD_FOLDER_02;
    //                    break;
    //                case 7:
    //                    //拼接返回空白音文件夹路径
    //                    path = AppPathConstant.PATH_APP_ROOT_FOLDER + File.separator +  userId + AppPathConstant.PATH_USER_SILENT_AUDIO_FOLDER;
    //                    break;
    //                case 8:
    //                    //拼接返回导出文件夹路径
    //                    path = AppPathConstant.PATH_APP_ROOT_FOLDER + File.separator +  userId + AppPathConstant.PATH_USER_OUTPUT_TXT_OR_WORD_FOLDER;
    //                    break;
    //                default:break;
    //            }
    //            if (RxFileTool.createOrExistsDir(path)) {
    //                return path;
    //            }
    //        }
    //        return null;
    //    }

    //    /**
    //     * 设置全部选中或不选中
    //     * @param userWorkList
    //     * @param isSelect
    //     */
    //    public static void setAllSelect(List<UserWork> userWorkList, boolean isSelect) {
    //        for (UserWork userWork : userWorkList){
    //            userWork.setSelect(isSelect);
    //        }
    //    }

    //    /**
    //     * 合并两个列表，并去除列表中重复的元素
    //     * @param audioList
    //     * @param newAudioList
    //     * @return audioList
    //     */
    //    public static void mergeData(List<UserWork> audioList, List<UserWork> newAudioList){
    //        List<UserWork> tempAudioList = new ArrayList<>();
    //        for (UserWork newAudio : newAudioList){
    //            boolean isE = false;
    //            for (UserWork audio : audioList){
    //                if (newAudio.getaPath().equals(audio.getaPath())){
    //                    isE = true;
    //                    break;
    //                }
    //            }
    //            if (!isE){
    //                tempAudioList.add(newAudio);
    //            }
    //        }
    //        if (tempAudioList.size() > 0){
    //            audioList.addAll(tempAudioList);
    //        }
    //    }

    /**
     * 获取一个线性布局管理器
     *
     * @param activity
     * @param isHorizontal 是否水平排序
     * @return
     */
    public static LinearLayoutManager getLlManager(Activity activity, boolean isHorizontal) {
        return new LinearLayoutManager(activity, isHorizontal ? RecyclerView.HORIZONTAL : RecyclerView.VERTICAL, false);
    }

    /**
     * 前往设置界面，无返回码
     *
     * @param activity
     */
    public static void toSettsing(Activity activity) {
        Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
        Uri uri = Uri.fromParts("package", activity.getApplicationContext().getPackageName(), null);
        intent.setData(uri);
        activity.startActivity(intent);
    }


    //    /**
    //     * 检查裁剪时间
    //     * @return
    //     */
    //    public static boolean checkClipTime(List<UserWork> userWorkList, UserInfo userInfo){
    //        long clipTime = 0;
    //        for (UserWork work : userWorkList){
    //            if (work.getPlayEndTime() == 0){
    //                work.setPlayEndTime(work.getDuration());
    //            }
    //            //累加裁剪时间
    //            clipTime += (work.getPlayEndTime() - work.getPlayStartTime());
    //        }
    //
    //        //判断裁剪时间是否超过两分钟
    //        if (clipTime > (1000 * 60 * 2)){
    //            //判断是否会员
    //            if (userInfo.getVipDay() <= 0 || !MyStrUtil.checkStr(userInfo.getVipEndTime())){
    //                return false;
    //            }
    //        }
    //        return true;
    //    }
    //
    //    /**
    //     * 检查混音数量
    //     * @return true:通过
    //     */
    //    public static boolean checkMixingNumber(List<UserWork> mUserWorkList, UserInfo mUserInfo){
    //        if (mUserWorkList.size() > 3){
    //            //判断是否会员
    //            if (mUserInfo.getVipDay() <= 0 || !MyStrUtil.checkStr(mUserInfo.getVipEndTime())){
    //                return false;
    //            }
    //        }
    //        return true;
    //    }

    //    /**
    //     * 检查作品后缀是否全部相同
    //     * @param workList
    //     * @return true:全部相同，false:workList为null,或存在不相同格式work
    //     */
    //    public static boolean checkAudioFormat(List<UserWork> workList){
    //        if (workList == null || workList.size() <= 0){
    //            return false;
    //        }
    //        String suffix = FileUtils.getFileSuffix(workList.get(0).getaPath());
    //        if (suffix == null){
    //            return false;
    //        }
    //        for (int i=1; i<workList.size(); i++){
    //            String suffix2 = FileUtils.getFileSuffix(workList.get(i).getaPath());
    //            if (!suffix.equals(suffix2)){
    //                return false;
    //            }
    //        }
    //        return true;
    //    }


    public static void lod(Activity activity, String str) {
        String name = activity.getComponentName().getClassName();
    }

    //    /**
    //     * 视频中提取链接
    //     * @param videoUrl
    //     * @return
    //     */
    //    public static String extractUrl(String videoUrl) {
    //        if (!MyStrUtil.checkStr(videoUrl)) {
    //            return null;
    //        }
    //        Pattern pattern = Pattern.compile("(?i)(http|https)://[^\u4e00-\u9fa5]+");
    //        Matcher m = pattern.matcher(videoUrl);
    //        while (m.find()) {
    //            if (m.group().length() > 7) {
    //                return m.group();
    //            }
    //        }
    //        return null;
    //    }

    /**
     * 获取缓存File路径
     *
     * @param context
     * @param type    缓存文件累心
     * @return
     */
    public static String getCacheFilePath(Context context, int type) {
        String path = null;
        switch (type) {
            case Constant.DYNAMIC_STICKER:
                String dynamicStickerPath;
                if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) {
                    dynamicStickerPath = context.getExternalFilesDir("dynamic_sticker").getPath();
                } else {
                    dynamicStickerPath = context.getFilesDir().getAbsolutePath() + File.separator + "dynamic_sticker";
                    FileUtils.createDirs(dynamicStickerPath);
                }
                path = dynamicStickerPath;
                break;
            case Constant.TTF:
                String ttfPath;
                if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) {
                    ttfPath = context.getExternalFilesDir("TTF").getPath();
                } else {
                    ttfPath = context.getFilesDir().getAbsolutePath() + File.separator + "TTF";
                    FileUtils.createDirs(ttfPath);
                }
                path = ttfPath;
                break;
            case Constant.VIDEO_BOX:
                String boxPath;
                if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) {
                    boxPath = context.getExternalFilesDir("box").getPath();
                } else {
                    boxPath = context.getFilesDir().getAbsolutePath() + File.separator + "box";
                    FileUtils.createDirs(boxPath);
                }
                path = boxPath;
                break;
            case Constant.SHAPE:
                String shapePath;
                if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) {
                    shapePath = context.getExternalFilesDir("shape").getPath();
                } else {
                    shapePath = context.getFilesDir().getAbsolutePath() + File.separator + "shape";
                    FileUtils.createDirs(shapePath);
                }
                path = shapePath;
                break;
            case Constant.MUSIC:
                String musicPath;
                if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) {
                    File baseDirFile = context.getExternalFilesDir(null);
                    if (baseDirFile==null){
                        musicPath = context.getFilesDir().getAbsolutePath() + File.separator + "bgMusic";
                        FileUtils.createDirs(musicPath);
                    }else {
                        musicPath =baseDirFile.getAbsolutePath();
                    }
                } else {
                    musicPath = context.getFilesDir().getAbsolutePath() + File.separator + "bgMusic";
                    FileUtils.createDirs(musicPath);
                }
                path = musicPath;
                break;
            case Constant.STICKER:
                String stickerPath;
                if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) {
                    stickerPath = context.getExternalFilesDir("sticker").getPath();
                } else {
                    stickerPath = context.getFilesDir().getAbsolutePath() + File.separator + "sticker";
                    FileUtils.createDirs(stickerPath);
                }
                path = stickerPath;
                break;

            case Constant.PICTURE:
                String picturePath;
                if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) {
                    picturePath = context.getExternalFilesDir("picture").getPath();
                } else {
                    picturePath = context.getFilesDir().getAbsolutePath() + File.separator + "picture";
                    FileUtils.createDirs(picturePath);
                }
                path = picturePath;
                break;
            case Constant.WATER:
                String waterPath;
                if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) {
                    waterPath = context.getExternalFilesDir("water").getPath();
                } else {
                    waterPath = context.getFilesDir().getAbsolutePath() + File.separator + "water";
                    FileUtils.createDirs(waterPath);
                }
                path = waterPath;
                break;
            case Constant.WATER_BG:
                String waterBgPath;
                if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) {
                    waterBgPath = context.getExternalFilesDir("waterBg").getPath();
                } else {
                    waterBgPath = context.getFilesDir().getAbsolutePath() + File.separator + "waterBg";
                    FileUtils.createDirs(waterBgPath);
                }
                path = waterBgPath;
                break;
            case Constant.MY_WATER_IMG:
                String myWaterPath;
                if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) {
                    myWaterPath = context.getExternalFilesDir("myWaterImg").getPath();
                } else {
                    myWaterPath = context.getFilesDir().getAbsolutePath() + File.separator + "myWaterImg";
                    FileUtils.createDirs(myWaterPath);
                }
                path = myWaterPath;
                break;
            case Constant.MY_WATER_DIY:
                String myWaterDiyPath;
                if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) {
                    myWaterDiyPath = context.getExternalFilesDir("myWaterDiy").getPath();
                } else {
                    myWaterDiyPath = context.getFilesDir().getAbsolutePath() + File.separator + "myWaterDiy";
                    FileUtils.createDirs(myWaterDiyPath);
                }
                path = myWaterDiyPath;
                break;
            default:
                break;
        }


        return path;
    }

}
